package lunchy.data.classes;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import lunchy.data.interfaces.ILunchyMenu;
import lunchy.data.interfaces.ILunchyMenuGroup;
import lunchy.data.interfaces.ILunchyUser;
import lunchy.data.interfaces.ILunchyUsersDAO;
import lunchy.util.CLunchyHibernateUtil;

public class CLunchyDBUsersDAO implements ILunchyUsersDAO
{
	public CLunchyDBUsersDAO()
	{
		
	}
	
	public ILunchyUser login(String login, String password)
	{
		Session session = null;
		List<ILunchyUser> users = null;
		
		try
		{
			session = CLunchyHibernateUtil.getSessionFactory().openSession();
			
			Query query = session.createQuery("from CLunchyUser where login = :login AND password = :password").setString("login", login).setString("password", password);	
			users = (List<ILunchyUser>) query.list();
			
			if(users.size() == 1)
				return users.get(0);
		}
		catch (Exception e)
		{
			
		}
		finally
		{
			if (session != null && session.isOpen())
				session.close();
		}

	    return null;
	}

}
